<template>
	<view>
		<image src="/static/xgbj.png" class="qjimg" mode=""></image>
		<view class="title">
			<image @click="fanhui" src="/static/zfh.png" :style="'margin-top:'+top+'px;'" mode=""></image>
			<view class="toptit" :style="'margin-top:'+top+'px;'">
				公共报修
			</view>
			<view class="" style="opacity: 0;">12</view>
		</view>

		<view class="box">
			<view class="" style="width: 231rpx;height: 40rpx;"></view>
			<view class="box_title">
				报修信息
			</view>
			<view class="box_2" style="margin-top: 20rpx;">
				<picker :range="range" :value="lxindex" @change="chaobianlx">
					<view class="box_2text">
						报修类别 <text>{{range[lxindex]}}</text>
					</view>
				</picker>
				<picker :range="list" :value="xmindex" @change="chaobianxm" range-key="title">
					<view class="box_2text">
						报修项目
						<view class="box_2text">
							<text>{{list[xmindex].title}}</text>
							<image src="../../static/yzk.png" style="width: 9rpx;height: 17rpx;margin-left:10rpx;"
								mode="">
							</image>
						</view>
					</view>
				</picker>
				<view class="box_2text">
					联系人
					<input type="text" placeholder="请填写姓名" v-model="name">
				</view>
			</view>

			<view class="box_2">
				<view class="box_2text">
					联系人电话
					<input type="text" placeholder="请填写电话" v-model="phone">
				</view>
				<picker :range="group" :value="bmindex" @change="chaobianbm" range-key="title">
					<view class="box_2text" style="border-bottom: #ffffff solid 2rpx;">
						所属部门：
						<view class="box_2text">
							<text>{{group[bmindex].title}}</text>
							<image src="../../static/yzk.png" style="width: 9rpx;height: 17rpx;margin-left:10rpx;"
								mode="">
						</view>
					</view>
				</picker>
			</view>
			<view class="box_title" style="margin-top: 80rpx;border-left: 8rpx solid #34d6c0;">
				报修内容
			</view>
			<view class="textarea" style="margin-top: 60rpx;">
				<textarea name="" id="" cols="30" rows="10" maxlength="50" v-model="content"
					placeholder="请填写详细报修内容，有助于工作人员快速帮您解决问题"></textarea>
				<view class="">
					{{content.length}}/50
				</view>
			</view>
			<view class="box_3">
				<image :src="item" v-for="(item,index) in tupian" :key="index" mode=""></image>
				<image src="/static/jiatp.png" mode="" @click="chooseImage"></image>
			</view>
			<view class="botton" @click="shangchuan">
				确认上报
			</view>

		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				top: 0,
				xungestate: 1,
				proid: '',
				range: ['公共报修', '个人保修'],
				name: '',
				lxindex: 0,
				bmindex: 0,
				xmindex: 0,
				list: [],
				phone: '',
				groupid: '',
				content: '',
				pics: [],
				tupian: [],
				address: '',
				group: []
			}
		},
		onLoad() {
			let menuButtonInfo = uni.getMenuButtonBoundingClientRect()
			this.top = menuButtonInfo.top * 1 + 10
			this.getinitbaoxiu()
			this.huoquaddress()
		},
		methods: {
			chaobianlx(e) {
				console.log(e.detail.value);
				this.lxindex = e.detail.value
				this.getinitbaoxiu()
			},
			chaobianxm(e) {
				this.xmindex = e.detail.value
			},
			chaobianbm(e) {
				this.bmindex = e.detail.value
			},
			getinitbaoxiu() {
				this.$post('wuyecenter/initbaoxiu', {
					type: this.lxindex + 1
				}, res => {
					this.list = res.data.list
					this.group = res.data.group
				})
			},
			huoquaddress() {
				this.$post('api/getuploadurl', {}, res => {
					this.address = res.data.url
					console.log(this.address);
				})
			},
			chooseImage() {
				var that = this
				uni.chooseImage({
					count: 1, //默认9
					sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图，默认二者都有
					sourceType: ['camera'], //从相册选择
					success: function(res) {
						// that.tupian = res.tempFilePaths
						that.uploadFile(res.tempFilePaths[0], '')
					}
				});
			},
			uploadFile(data, state) {
				var that = this
				uni.uploadFile({
					url: that.address, //仅为示例，非真实的接口地址
					filePath: data,
					name: 'file',
					fileType: 'image',
					formData: {
						'user': 'test'
					},
					success: (uploadFileRes) => {
						const tupian = JSON.parse(uploadFileRes.data)
						if (state) {
							console.log(tupian.data.url);
						} else {
							that.tupian.push(tupian.data.url)
						}


					}
				});
			},
			xungeng(e) {
				this.xungestate = e
			},
			shangchuan() {
				this.$post('wuyecenter/upbaoxiu', {
					type: this.lxindex + 1,
					content: this.content,
					name: this.name,
					phone: this.phone,
					pics: this.tupian,
					proid: this.list[this.xmindex].id,
					groupid: this.group[this.bmindex].id,
				}, res => {
					uni.showToast({
						title: res.msg,
						icon: 'none'
					})
					setTimeout(res => {
						uni.switchTab({
							url: '/pages/index/index'
						})
					}, 1500)
				})
			},
			fanhui() {
				uni.switchTab({
					url: '/pages/index/index'
				})
			}
		}
	}
</script>

<style lang="scss">
	page {
		background-color: rgb(255, 255, 255);
	}

	.qjimg {
		width: 750rpx;
		height: 603rpx;
		position: absolute;
		top: 0;
		z-index: -1;
	}

	.toptit {
		font-size: 36rpx;
		font-family: Source Han Sans CN;
		font-weight: 500;
		color: #FFFFFF;
		line-height: 20rpx;
	}

	.title {
		display: flex;
		justify-content: space-between;
		align-items: center;

		>image {
			width: 12rpx;
			height: 24rpx;
			margin-left: 30rpx;
		}
	}

	.top {
		display: flex;
		margin-left: 46rpx;
		margin-top: 50rpx;

		>image {
			width: 97rpx;
			height: 97rpx;
		}
	}

	.top1 {
		margin-left: 16rpx;
		display: flex;
		flex-direction: column;
		justify-content: space-between;
	}

	.top1text {
		font-size: 30rpx;
		font-family: Source Han Sans CN;
		font-weight: 500;
		color: #FFFFFF;
		line-height: 50rpx;
	}

	.top1text1 {
		font-size: 22rpx;
		font-family: Source Han Sans CN;
		font-weight: 400;
		color: #FFFFFF;
		line-height: 50rpx;
	}

	.box {
		background-color: #FFFFFF;
		width: 90vw;
		margin: 60rpx auto;
		border-radius: 20rpx;
	}

	.box_1 {
		display: flex;
		align-items: center;
		padding: 20rpx;

		>image {
			width: 94rpx;
			height: 94rpx;
		}
	}

	.box_1-1 {
		margin-left: 10rpx;
	}

	.box_1-1text {
		font-size: 30rpx;
		font-family: Source Han Sans CN;
		font-weight: 500;
		color: #333333;
		// line-height: 20rpx;
	}

	.box_1-1text1 {
		font-size: 24rpx;
		font-family: Source Han Sans CN;
		font-weight: 400;
		color: #999999;
		// line-height: 20rpx;
	}

	.box_title {
		border-left: 8rpx solid #4ab6f9;
		width: 160rpx;
		text-align: center;
		font-size: 30rpx;
		font-family: Source Han Sans CN;
		font-weight: 500;
		color: #333333;
		// line-height: 20rpx;
	}

	.box_2 {
		width: 636rpx;
		margin: 0rpx auto;
	}

	.box_2text {

		font-size: 24rpx;
		font-family: Source Han Sans CN;
		font-weight: 400;
		color: #333333;
		// line-height: 20rpx;
		// margin: 30rpx 0;
		display: flex;
		justify-content: space-between;
		align-items: center;
		line-height: 100rpx;
		border-bottom: #f6f6f6 solid 2rpx;

		>text {
			color: #999999;
		}

		>input {
			width: 120rpx;
		}
	}

	.texta {
		width: 91%;
		height: 170rpx;
		margin: 0 auto;
		background-color: #f6f6f6;
	}

	.box_3 {
		// width: 91%;
		margin: 50rpx auto;
		display: flex;

		>image {
			margin: 10rpx;
			width: 158rpx;
			height: 158rpx;
		}
	}

	.button {
		width: 498rpx;
		height: 70rpx;
		margin: 0 auto;
		margin-top: 100rpx;
		color: #FFFFFF;
		text-align: center;
		background-color: #2e79f9;
		border-radius: 35rpx;
		line-height: 70rpx;
	}

	.textarea {
		width: 646rpx;
		height: 202rpx;
		background-color: #eeeeee;

		>textarea {
			margin: 0 auto;
			padding-top: 30rpx;
			width: 598rpx;
			height: 130rpx;
			font-size: 24rpx;
			font-family: Source Han Sans CN;
			font-weight: 400;
			color: #999999;
		}

		>view {
			position: relative;
			left: 571rpx;
			font-size: 24rpx;
			font-family: Source Han Sans CN;
			font-weight: 400;
			color: #999999;
		}
	}

	.botton {
		width: 498rpx;
		height: 70rpx;
		background-color: #2e79f9;
		border-radius: 35rpx;
		margin: 0 auto;
		text-align: center;
		font-size: 24rpx;
		font-family: Source Han Sans CN;
		font-weight: 500;
		color: #FFFFFF;
		line-height: 70rpx;
	}
</style>
